﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel.Composition;
using RenderEngineInterfaces;
using DeepZoomPivotConstructor.VisualLib;
using System.Threading.Tasks;
using System.IO;
using System.Drawing;

namespace t_RenderTestingLibrary
{
    public class Utilities
    {
        public static void AddJPEGFileInfoRender()
        {
            t_TestingLibrary.Utilities.AddPart(new RenderJpegFromFileInfo());
        }

        public static void AddJPEGRender()
        {
            RenderJpegFromString j = new RenderJpegFromString();
            t_TestingLibrary.Utilities.AddPart(j);
        }

        public static void AddPSFileInfoRender()
        {
            t_TestingLibrary.Utilities.AddPart(new RenderPSFromFileInfo());
        }

        public static void AddPSFileInfoRenderHigh()
        {
            t_TestingLibrary.Utilities.AddPart(new RenderPSFromFileInfoHigh());
        }

        [Export(typeof(IRenderItem))]
        [RenderInfo(typeof(string))]
        class RenderJpegFromString : IRenderItem, IRenderableObjectCompare
        {
            #region IRenderItem Members

            public Task<Visual> Render(object what)
            {
                return Task<Visual>.Factory.StartNew(() =>
                {
                    Visual result = new VisualBitmapImage(1, 2, 100, Color.Red);
                    return result;
                });
            }

            public RenderPluginPriority RenderPriority(object what)
            {
                string f = what as string;
                if (f.EndsWith(".jpeg") || f.EndsWith(".jpg"))
                {
                    return RenderPluginPriority.RPPGeneric;
                }
                return RenderPluginPriority.RPPCantDoIt;
            }

            #endregion

            /// <summary>
            /// Return the hash for teh object.
            /// </summary>
            /// <param name="what"></param>
            /// <returns></returns>
            public long GetObjectHash(object what)
            {
                return what.GetHashCode();
            }

            public bool ObjectsEqual(object o1, object o2)
            {
                throw new NotImplementedException();
            }

            public bool IsOutOfDate(object what, object metaData)
            {
                throw new NotImplementedException();
            }

            public object GetObjectDateMetaData(object what)
            {
                return 123546;
            }
        }

        [Export(typeof(IRenderItem))]
        [RenderInfo(typeof(FileInfo))]
        public class RenderJpegFromFileInfo : IRenderItem
        {
            #region IRenderItem Members

            public Task<Visual> Render(object what)
            {
                return Task<Visual>.Factory.StartNew(() =>
                {
                    Visual result = new VisualBitmapImage(1, 2, 100, Color.Red);
                    return result;
                });
            }

            public RenderPluginPriority RenderPriority(object what)
            {
                FileInfo f = what as FileInfo;
                if (f.Extension == ".jpeg" || f.Extension == ".jpg")
                {
                    return RenderPluginPriority.RPPGeneric;
                }
                return RenderPluginPriority.RPPCantDoIt;
            }

            #endregion
        }

        [Export(typeof(IRenderItem))]
        [RenderInfo(typeof(FileInfo))]
        class RenderPSFromFileInfo : IRenderItem
        {
            #region IRenderItem Members

            public Task<Visual> Render(object what)
            {
                return Task<Visual>.Factory.StartNew(() =>
                {
                    Visual result = new VisualBitmapImage(2, 3, 100, Color.Red);
                    return result;
                });
            }

            public RenderPluginPriority RenderPriority(object what)
            {
                FileInfo f = what as FileInfo;
                if (f.Extension == ".ps" || f.Extension == ".eps")
                {
                    return RenderPluginPriority.RPPGeneric;
                }
                return RenderPluginPriority.RPPCantDoIt;
            }

            #endregion
        }

        [Export(typeof(IRenderItem))]
        [RenderInfo(typeof(FileInfo))]
        class RenderPSFromFileInfoHigh : IRenderItem
        {
            #region IRenderItem Members

            public Task<Visual> Render(object what)
            {
                return Task<Visual>.Factory.StartNew(() =>
                {
                    Visual result = new VisualBitmapImage(3, 4, 100, Color.Red);
                    return result;
                });
            }

            public RenderPluginPriority RenderPriority(object what)
            {
                FileInfo f = what as FileInfo;
                if (f.Extension == ".ps" || f.Extension == ".eps")
                {
                    return RenderPluginPriority.RPPSpecific;
                }
                return RenderPluginPriority.RPPCantDoIt;
            }

            #endregion
        }
    }
}
